package cn.zlj.nmcc.mq;

import cn.zlj.nmcc.domain.MediaFile;
import cn.zlj.nmcc.service.IMediaFileService;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
@Component
@RocketMQMessageListener(
        consumerGroup = "service-media-consumer",
        topic = "media-push-topic",
        selectorExpression = "media-push-tag"
)
public class MediaFileConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private IMediaFileService mediaFileService;

    @Override
    public void onMessage(MessageExt messageExt) {
        String mediaFileJsonStr = new String(messageExt.getBody(),StandardCharsets.UTF_8);
        MediaFile mediaFile = JSONObject.parseObject(mediaFileJsonStr, MediaFile.class);
        mediaFileService.handleFile2m3u8(mediaFile);
    }
}
